home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 346 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: solon.com!not-for-mail
  2. From: fred@genesis.demon.co.uk (Lawrence Kirby)
  3. Newsgroups: comp.lang.c.moderated,comp.std.c
  4. Subject: Integral promotion.
  5. Date: 21 Feb 1996 09:31:02 -0600
  6. Organization: none
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4gfdrm$2vs@solutions.solon.com>
  10. Reply-To: fred@genesis.demon.co.uk
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Mailer: Demon Internet Simple News v1.27
  13.  
  14. In article <4g55fl$avl@solutions.solon.com> msb@sq.com  writes:
  15.  
  16.  > > > short test(short x1, short x2) {
  17.  > > >  short result;
  18.  > > >  result = x1 + x2;
  19.  > > 
  20.  > > The addition operator "+" converts your short operands to ints.
  21.  > 
  22.  > No, just using their values does that.  The operator + never sees
  23.  > operands narrower than int.  In the statement
  24.  >         x1; 
  25.  > the short is converted to int before being discarded.
  26.  
  27. This does however beg a question regarding the standard. Take the
  28. >> or << operators. In 6.3.7 we have:
  29.  
  30. "Constraints
  31.  
  32.      Each of the operands shall have integral type
  33.  
  34.  Semantics
  35.  
  36.      The integral promotions are performed on each of the operands..."
  37.  
  38. If the operator never sees operands narrower than int then this sentence
  39. is pointless.
  40.  
  41. -- 
  42. -----------------------------------------
  43. Lawrence Kirby | fred@genesis.demon.co.uk
  44. Wilts, England | 70734.126@compuserve.com
  45. -----------------------------------------
  46.